package com.example.pulseanalyse.veinType;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

/**
 * @author: yyw
 * time: 2020/12/8 11:48
 * desc:
 */
public interface synPulseType1 {
    /// <summary>
    /// 返回综合脉型
    /// </summary>
    /// <param name="_synList">浮脉型+中脉型+沉脉型</param>
    /// <param name="_synMax">最佳脉图脉型</param>
    /// <returns></returns>
    String returnPulseType(List<String> _synList, String _synMax);
}

/// <summary>
/// 促、结、代脉 替换/添加  促结代同时出现时  根据脉率去掉促 根据脉律去掉代
/// </summary>
class synCu implements synPulseType1 {
    public String returnPulseType(List<String> _synList, String _synMax) {
        String _strResult = _synMax;
        if (!_strResult.contains("促") && !_strResult.contains("结") && !_strResult.contains("代")) {
            if (_synList.contains("促") || _synList.contains("结") || _synList.contains("代")) {
                for (int i = 0; i < _synList.size(); i++) {
                    if (_synList.get(i) == "促" || _synList.get(i) == "结" || _synList.get(i) == "代") {
                        _strResult += "," + _synList.get(i);
                    }
                }
            }
        } else {
            for (int i = 0; i < _synList.size(); i++) {
                if (!_strResult.contains(_synList.get(i)) && (_synList.get(i) == "促" || _synList.get(i) == "结" || _synList.get(i) == "代")) {
                    _strResult += "," + _synList.get(i);
                }
            }
        }

        String _str = replaceType(_strResult);

        if (_str.contains(",")) {
            String _strResult1 = "";
            String[] _strSplit = _str.split(",");
            for (int i = 0; i < _strSplit.length; i++) {
                if (_strSplit[i] != "") {
                    _strResult1 += _strSplit[i] + ",";
                }
            }
            if (_strResult1 != "") {
                _strResult1 = _strResult1.substring(0, _strResult1.length() - 1);
            }
            return _strResult1;
        } else {
            return _strResult;
        }
    }

    private String replaceType(String _synMax) {
        String _strResult = _synMax;
        if (_strResult.contains("促") && (_strResult.contains("结") || _strResult.contains("代"))) {
            _strResult = _strResult.replace("促", "");
        }
        if (_strResult.contains("结") && _strResult.contains("代")) {
            _strResult = _strResult.replace("代", "");
        }
        return _strResult;
    }
}

/// <summary>
/// 疾、数、缓、迟 替换/添加
/// </summary>
class synPulseRate implements synPulseType1 {

    public String returnPulseType(List<String> _synList, String _synMax) {
        String _strResult = _synMax;
        if (!_strResult.contains("疾") && !_strResult.contains("数") && !_strResult.contains("实") && !_strResult.contains("平") && !_strResult.contains("缓") && !_strResult.contains("迟")) {
            if (_synList.contains("疾") || _synList.contains("数") || _synList.contains("实") || _synList.contains("平") || _synList.contains("缓") || _synList.contains("迟")) {
                for (int i = 0; i < _synList.size(); i++) {
                    if (_synList.get(i) == "疾" || _synList.get(i) == "数" || _synList.get(i) == "缓" || _synList.get(i) == "迟" || _synList.contains("实") || _synList.contains("平")) {
                        _strResult += "," + _synList.get(i);
                    }
                }
            }
        } else {
            for (int i = 0; i < _synList.size(); i++) {
                if (!_strResult.contains(_synList.get(i)) && (_synList.get(i) == "疾" || _synList.get(i) == "数" || _synList.get(i) == "缓" || _synList.get(i) == "迟" || _synList.contains("实") || _synList.contains("平"))) {
                    _strResult += "," + _synList.get(i);
                }
            }
        }

        String _str = replaceType(_strResult);

        if (_str.contains(",")) {
            String _strResult1 = "";
            String[] _strSplit = _str.split(",");
            for (int i = 0; i < _strSplit.length; i++) {
                if (_strSplit[i] != "") {
                    _strResult1 += _strSplit[i] + ",";
                }
            }
            if (_strResult1 != "") {
                _strResult1 = _strResult1.substring(0, _strResult1.length() - 1);
            }
            return _strResult1;
        } else {
            return _strResult;
        }
    }

    private String replaceType(String _synMax) {
        String _strResult = _synMax;
        if (_strResult.contains("疾") && (_strResult.contains("数") || _strResult.contains("实") || _strResult.contains("平") || _strResult.contains("缓") || _strResult.contains("迟"))) {
            _strResult = _strResult.replace("疾", "");
        }
        if (_strResult.contains("数") && (_strResult.contains("实") || _strResult.contains("缓") || _strResult.contains("迟") || _strResult.contains("平"))) {
            _strResult = _strResult.replace("数", "");
        }
        if (_strResult.contains("实") && (_strResult.contains("缓") || _strResult.contains("迟"))) {
            _strResult = _strResult.replace("实", "");
        }
        if (_strResult.contains("平") && (_strResult.contains("缓") || _strResult.contains("迟"))) {
            _strResult = _strResult.replace("平", "");
        }
        if (_strResult.contains("缓") && _strResult.contains("迟")) {
            _strResult = _strResult.replace("缓", "");
        }
        if (_strResult.contains("促") && (_strResult.contains("实") || _strResult.contains("缓") || _strResult.contains("迟"))) {
            _strResult = _strResult.replace("促", "");
        }

        return _strResult;
    }
}

/// <summary>
/// 滑脉  减脉型
/// </summary>
class synSlippery implements synPulseType1 {
    public String returnPulseType(List<String> _synList, String _synMax) {
        String _strResult = _synMax;

        if (_strResult.contains("滑")) {


            Map<String, List<String>> listMap1 = GroupingUtil.dividerStrList2(_synList);
            for (String key1 : listMap1.keySet()) {
                if ("无".equals(key1) && listMap1.get(key1).size() == 1) {
                    Map<String, List<String>> listMap2 = GroupingUtil.dividerStrList2(_synList);
                    for (String key2 : listMap2.keySet()) {
                        if ("滑".equals(key2) && listMap2.get(key2).size() < 2) {
                            _strResult = _strResult.replace("滑", "");
                            break;
                        }
                    }
                    break;
                }
            }

//            foreach(var item in _synList.GroupBy(c = > c))
//            {
//                if (item.Key == "无" && item.Count() == 1) {
//                    foreach(var item1 in _synList.GroupBy(c = > c))
//                    {
//                        if (item1.Key == "滑" && item1.Count() < 2) {
//                            _strResult = _strResult.Replace("滑", "");
//                            break;
//                        }
//                    }
//                    break;
//                }
//            }
        }

        if (_strResult.contains(",")) {
            String _strResult1 = "";
            String[] _strSplit = _strResult.split(",");
            for (int i = 0; i < _strSplit.length; i++) {
                if (_strSplit[i] != "") {
                    _strResult1 += _strSplit[i] + ",";
                }
            }
            if (_strResult1 != "") {
                _strResult1 = _strResult1.substring(0, _strResult1.length() - 1);
            }
            return _strResult1;
        } else {
            return _strResult;
        }
    }
}


/// <summary>
/// 涩脉 减脉型
/// </summary>
class synRough implements synPulseType1 {
    public String returnPulseType(List<String> _synList, String _synMax) {
        String _strResult = _synMax;

        if (_strResult.contains("涩")) {


            Map<String, List<String>> listMap1 = GroupingUtil.dividerStrList2(_synList);
            for (String key1 : listMap1.keySet()) {
                if ("无".equals(key1) && listMap1.get(key1).size() == 1) {
                    Map<String, List<String>> listMap2 = GroupingUtil.dividerStrList2(_synList);
                    for (String key2 : listMap2.keySet()) {
                        if ("涩".equals(key2) && listMap2.get(key2).size() < 2) {
                            _strResult = _strResult.replace("涩", "");
                            break;
                        }
                    }
                    break;
                }
            }

//            foreach(var item in _synList.GroupBy(c = > c))
//            {
//                if (item.Key == "无" && item.Count() == 1) {
//                    foreach(var item1 in _synList.GroupBy(c = > c))
//                    {
//                        if (item1.Key == "涩" && item1.Count() < 2) {
//                            _strResult = _strResult.Replace("涩", "");
//                            break;
//                        }
//                    }
//                    break;
//                }
//            }

        }

        if (_strResult.contains(",")) {
            String _strResult1 = "";
            String[] _strSplit = _strResult.split(",");
            for (int i = 0; i < _strSplit.length; i++) {
                if (_strSplit[i] != "") {
                    _strResult1 += _strSplit[i] + ",";
                }
            }
            if (_strResult1 != "") {
                _strResult1 = _strResult1.substring(0, _strResult1.length() - 1);
            }
            return _strResult1;
        } else {
            return _strResult;
        }

    }
}

/// <summary>
/// 弦脉  减脉型
/// </summary>
class synStringy implements synPulseType1 {
    public String returnPulseType(List<String> _synList, String _synMax) {
        String _strResult = _synMax;

        if (_strResult.contains("弦")) {

            Map<String, List<String>> listMap1 = GroupingUtil.dividerStrList2(_synList);
            for (String key1 : listMap1.keySet()) {
                if ("无".equals(key1) && listMap1.get(key1).size() == 1) {
                    Map<String, List<String>> listMap2 = GroupingUtil.dividerStrList2(_synList);
                    for (String key2 : listMap2.keySet()) {
                        if ("弦".equals(key2) && listMap2.get(key2).size() < 2) {
                            _strResult = _strResult.replace("弦", "");
                            break;
                        }
                    }
                    break;
                }
            }

//            foreach(var item in _synList.GroupBy(c = > c))
//            {
//                if (item.Key == "无" && item.Count() == 1) {
//                    foreach(var item1 in _synList.GroupBy(c = > c))
//                    {
//                        if (item1.Key == "弦" && item1.Count() < 2) {
//                            _strResult = _strResult.Replace("弦", "");
//                            break;
//                        }
//                    }
//                    break;
//                }
//            }
        }

        if (_strResult.contains(",")) {
            String _strResult1 = "";
            String[] _strSplit = _strResult.split(",");
            for (int i = 0; i < _strSplit.length; i++) {
                if (_strSplit[i] != "") {
                    _strResult1 += _strSplit[i] + ",";
                }
            }
            if (_strResult1 != "") {
                _strResult1 = _strResult1.substring(0, _strResult1.length() - 1);
            }
            return _strResult1;
        } else {
            return _strResult;
        }
    }
}


/// <summary>
/// 平脉
/// </summary>
class synNormal implements synPulseType1 {
    public String returnPulseType(List<String> _synList, String _synMax) {
        String _strResult = _synMax;

        if (_strResult.contains("无")) {
            _strResult = _strResult.replace("无", "");
        }

        if (myHelper.GetHanNumFromString(_strResult) > 1 && _strResult.contains("平")) {
            _strResult = _strResult.replace("平", "");
        }

        if (_strResult.contains(",")) {
            String _strResult1 = "";
            String[] _strSplit = _strResult.split(",");

            //去重操作
            List<String> list = new ArrayList<>();
            for (int i = 0; i < _strSplit.length; i++) {
                list.add(_strSplit[i]);
            }
            HashSet hashSet = new HashSet(list);
            list.clear();
            list.addAll(hashSet);
            for (int i = 0; i < list.size(); i++) {
                _strSplit[i]=list.get(i);
            }

//            _strSplit = _strSplit.Distinct().ToArray();
            for (int i = 0; i < _strSplit.length; i++) {
                if (_strSplit[i] != "") {
                    _strResult1 += _strSplit[i] + ",";
                }
            }
            if (_strResult1 != "") {
                _strResult1 = _strResult1.substring(0, _strResult1.length() - 1);
            }
            return _strResult1;
        } else {
            return _strResult;
        }
    }
}
